/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DomainSpecialistView.java
 *
 * Created on 10-Jan-2012, 23:11:48
 */
package blackeagle.ems;

import blackeagle.ems.entities.Domain;
import blackeagle.ems.entities.DomainCollection;
import blackeagle.ems.entities.Employee;
import blackeagle.ems.entities.EmployeeCollection;
import org.jdesktop.application.Action;
import se.oru.informatik.InformatikDB;
import se.oru.informatik.InformatikException;
import se.oru.informatik.StringHelper;

/**
 *
 * @author Martin
 */
public class DomainSpecialistView extends javax.swing.JDialog {

    /** Creates new form DomainSpecialistView */
    public DomainSpecialistView(java.awt.Frame parent) {
        super(parent, true);
        this.setTitle("Edit Specialist Levels");
        initComponents();
        
        EmployeeCollection ec = new EmployeeCollection().load();
        for(Employee e : ec){
            this.cbEmployees.addItem(e);
        }
        
        DomainCollection dc = new DomainCollection().load();
        for(Domain d : dc){
            this.cbDomains.addItem(d);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cbEmployees = new javax.swing.JComboBox();
        lblEmployee = new javax.swing.JLabel();
        lblDomain = new javax.swing.JLabel();
        lblLevel = new javax.swing.JLabel();
        cbDomains = new javax.swing.JComboBox();
        btnSave = new javax.swing.JButton();
        cbLevels = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        cbEmployees.setName("cbEmployees"); // NOI18N

        lblEmployee.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblEmployee.setText("Employee");
        lblEmployee.setName("lblEmployee"); // NOI18N

        lblDomain.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblDomain.setText("Domain");
        lblDomain.setName("lblDomain"); // NOI18N

        lblLevel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblLevel.setText("Level");
        lblLevel.setName("lblLevel"); // NOI18N

        cbDomains.setName("cbDomains"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(DomainSpecialistView.class, this);
        btnSave.setAction(actionMap.get("btnSave_click")); // NOI18N
        btnSave.setText("Save");
        btnSave.setName("btnSave"); // NOI18N

        cbLevels.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "No Competence", "Level 1", "Level 2", "Level 3" }));
        cbLevels.setName("cbLevels"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbEmployees, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblEmployee))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbDomains, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDomain))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblLevel)
                    .addComponent(cbLevels, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(589, Short.MAX_VALUE)
                .addComponent(btnSave)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEmployee)
                    .addComponent(lblDomain)
                    .addComponent(lblLevel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbEmployees, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbDomains, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbLevels, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addComponent(btnSave)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void btnSave_click() {
        Employee e = (Employee)this.cbEmployees.getSelectedItem();
        Domain d = (Domain)this.cbDomains.getSelectedItem();
        Integer i = this.cbLevels.getSelectedIndex();
        
        InformatikDB iDB = null;
        String result = null, query = StringHelper.sprintf("SELECT DS.\"LEVEL\" FROM DOMAINSPECIALIST AS DS WHERE DS.EMPLOYEEID='#' AND DS.DOMAINID='#'", e.getId(), d.getId());
        try{
            iDB = new InformatikDB(BlackEagleEMS.connectionString);
            result = iDB.fetchSingle(query);
        }catch(InformatikException ex){
            return;
        }
        
        if(i==0){
            // delete connection
        }else{
            
        }
        
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSave;
    private javax.swing.JComboBox cbDomains;
    private javax.swing.JComboBox cbEmployees;
    private javax.swing.JComboBox cbLevels;
    private javax.swing.JLabel lblDomain;
    private javax.swing.JLabel lblEmployee;
    private javax.swing.JLabel lblLevel;
    // End of variables declaration//GEN-END:variables
}
